package com.aierjun.ani.widget.title;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aierjun.ani.R;


/**
 * Created by aierJun on 2017/4/23.
 */
public  class LeftImgTitleRightTwoTextBar extends RelativeLayout {
    private String RightOneText;
    private String RightTwoText;
    private Drawable LeftImg;
    private String TitleText;
    private float TitleTextSize=0;
    private float RightTextSize=0;
    private int BarBackground=0;
    private int TextColor=0;
    private TextView textViewRightTwo;
    private ImageView imageViewLeft;
    private TextView title;
    private TextView textViewRightOne;

    private LeftImgTitleRightTwoTextOnClickLister leftImgTitleRightTwoTextOnClickLister;

    public LeftImgTitleRightTwoTextBar(Context context) {
        super(context);
    }

    public LeftImgTitleRightTwoTextBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        View view= LayoutInflater.from(context).inflate(R.layout.leftimg_title_righttwotext_bar_layout, this);
        RelativeLayout relativeLayout= (RelativeLayout) view.findViewById(R.id.leftImgTitleRightImgBar_relativelayout);
        imageViewLeft= (ImageView) view.findViewById(R.id.leftImgTitleRightImgBar_left_image);
        title= (TextView) view.findViewById(R.id.leftImgTitleRightImgBar_title_text);
        textViewRightTwo= (TextView) view.findViewById(R.id.leftImgTitleRightImgBar_right_two_text);
        textViewRightOne= (TextView) view.findViewById(R.id.leftImgTitleRightImgBar_right_one_text);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LeftImgTitleRightTwoTextBar);
        BarBackground=ta.getColor(R.styleable.LeftImgTitleRightTwoTextBar_leftImgTitleRightTwoTextBarBackgroundColor,0);
        LeftImg=ta.getDrawable(R.styleable.LeftImgTitleRightTwoTextBar_leftImgTitleRightTwoTextBarLeftImg);
        RightOneText=ta.getString(R.styleable.LeftImgTitleRightTwoTextBar_leftImgTitleRightTwoTextBarRightOneText);
        RightTwoText=ta.getString(R.styleable.LeftImgTitleRightTwoTextBar_leftImgTitleRightTwoTextBarRightTwoText);
        TextColor=ta.getColor(R.styleable.LeftImgTitleRightTwoTextBar_leftImgTitleRightTwoTextBarTextColor,0);
        RightTextSize=ta.getDimension(R.styleable.LeftImgTitleRightTwoTextBar_leftImgTitleRightTwoTextBarRightTextSize,12);
        TitleTextSize=ta.getDimension(R.styleable.LeftImgTitleRightTwoTextBar_leftImgTitleRightTwoTextBarTitleTextSize,10);
        TitleText=ta.getString(R.styleable.LeftImgTitleRightTwoTextBar_leftImgTitleRightTwoTextBarTitleText);
        if (BarBackground!=0) relativeLayout.setBackgroundColor(BarBackground);
        if (LeftImg!=null) imageViewLeft.setImageDrawable(LeftImg);
        if (RightTwoText!=null) textViewRightTwo.setText(RightTwoText);
        if (RightOneText!=null) textViewRightOne.setText(RightOneText);
        if (TextColor!=0){title.setTextColor(TextColor);textViewRightOne.setTextColor(TextColor);textViewRightTwo.setTextColor(TextColor);}
        if (RightTextSize!=0) {textViewRightOne.setTextSize(RightTextSize);textViewRightTwo.setTextSize(RightTextSize);}
        if (TitleTextSize!=0) title.setTextSize(TitleTextSize);
        if (TitleText!=null) title.setText(TitleText);
        imageViewLeft.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                leftImgTitleRightTwoTextOnClickLister.setLeftImgOnClickLister();
            }
        });
        textViewRightOne.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                leftImgTitleRightTwoTextOnClickLister.setRightOneOnClickLister();
            }
        });
        textViewRightTwo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                leftImgTitleRightTwoTextOnClickLister.setRightTwoOnClickLister();
            }
        });
    }


    public void setTitleTextSize(float titleTextSize) {
        title.setTextSize(titleTextSize);
    }

    public void setRightTextSize(float rightTextSize) {
        textViewRightOne.setTextSize(rightTextSize);
        textViewRightTwo.setTextSize(rightTextSize);
    }

    public String getRightOneText() {
        return textViewRightOne.getText().toString();
    }


    public String getRightTwoText() {
        return textViewRightTwo.getText().toString();
    }

    public String getTitleText() {
        return title.getText().toString();
    }
    public void setRightOneText(String rightOneText) {
        textViewRightOne.setText(rightOneText);
    }

    public void setRightTwoText(String rightTwoText) {
        textViewRightTwo.setText(rightTwoText);
    }

    public void setTitleText(String titleText) {
        title.setText(titleText);
    }

    public void setLeftImgTitleRightTwoTextOnClickLister(LeftImgTitleRightTwoTextOnClickLister leftImgTitleRightTwoTextOnClickLister){
        this.leftImgTitleRightTwoTextOnClickLister=leftImgTitleRightTwoTextOnClickLister;
    }
    public interface LeftImgTitleRightTwoTextOnClickLister {

        void setLeftImgOnClickLister();

        void setRightOneOnClickLister();

        void setRightTwoOnClickLister();
    }

}
